package page.Beans;

import java.sql.Date;
import java.sql.SQLException;
import java.util.List;

import basicTypes.RAClient;
import basicTypes.RAReserve;

public class recDevolution {
	private String user;
	private String recId;
	private String data;
	private String hora;
	
	public String getRecId() {
		return recId;
	}
	public void setRecId(String recId) {
		this.recId = recId;
	}
	public String getData() {
		return data;
	}
	public void setData(String data) {
		this.data = data;
	}
	public String getHora() {
		return hora;
	}
	public void setHora(String hora) {
		this.hora = hora;
	}
	
	
	public String recDevol(loginBean x) throws SQLException{
		RAClient usr;
		
		try{
			usr = x.getBd().db_getClient(x.getUser(), user).get(0);
		}
		catch(IndexOutOfBoundsException e){
			return "fail";
		}
		
		RAReserve novo = new RAReserve(usr.getId(), Integer.valueOf(recId).intValue(), Date.valueOf(data), hora);
		
		boolean var = false;
		
		List<RAReserve> lista = x.getBd().db_getReserves(x.getUser(), usr);
		
		for(int i = 0; i < lista.size(); i++){
			if(lista.get(i).compareTo(novo)==0){
				var=true;
				break;
			}
		}
		if(var){
			x.getBd().db_delReserve(x.getUser(), novo);
			return "suc";
		}
		
		return "fail";
			
		
		
	}
	public String getUser() {
		return user;
	}
	public void setUser(String user) {
		this.user = user;
	}
}
